package com.yzt.message.util;

import android.text.TextUtils;

import com.yzt.zhuju.RXingUtils;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import io.rong.imlib.model.Conversation;

/**
 * desc   : 置顶权限人员管理类
 */
public class UserInfoManager {

    private static UserInfoManager mInstance;

    /**
     * 置顶人员id列表
     */
    private final List<String> topPrivilegeUserList = new ArrayList<>();

    private final List<String> goodFriendList = new ArrayList<>();

    private final List<String> onLineList = new ArrayList<>();

    private final Set<String> intimacyList = new HashSet<>();

    private UserInfoManager() {

    }

    public static UserInfoManager getInstance() {
        synchronized (UserInfoManager.class) {
            if (mInstance == null) {
                mInstance = new UserInfoManager();
            }
        }
        return mInstance;
    }

    public List<String> getTopPrivilegeUserList() {
        return topPrivilegeUserList;
    }

    public void setTopPrivilegeUserList(List<String> list) {
        topPrivilegeUserList.clear();
        topPrivilegeUserList.addAll(list);
    }

    public void addTopPrivilegeUserList(List<String> list) {
        topPrivilegeUserList.addAll(list);
    }

    public void addTopPrivilegeUser(String id) {
        topPrivilegeUserList.add(id);
    }

    public void removeTopPrivilegeUser(String id) {
        topPrivilegeUserList.remove(id);
    }

    public boolean isTopPrivilegeUser(String id) {
        return topPrivilegeUserList.contains(id);
    }

    public boolean isOnline(String id) {
        return onLineList.contains(id);
    }

    public List<String> getOnLineList() {
        return onLineList;
    }

    public void setOnLineList(List<String> onLineList) {
        this.onLineList.clear();
        this.onLineList.addAll(onLineList);
    }

    public void addOnLineList(List<String> onLineList) {
        this.onLineList.addAll(onLineList);
    }

    public void setIntimacyList(List<String> intimacyList) {
        this.intimacyList.addAll(intimacyList);
    }

    public boolean isIntimacy(String uid) {
        return this.intimacyList.contains(uid);
    }

    public List<String> getGoodFriendList() {
        return goodFriendList;
    }

    public void setGoodFriendList(List<String> list) {
        goodFriendList.clear();
        goodFriendList.addAll(list);
    }

    public void addGoodFriendList(List<String> list) {
        goodFriendList.addAll(list);
    }

    public void addGoodFriend(String id) {
        goodFriendList.add(id);
    }

    public void removeGoodFriend(String id) {
        goodFriendList.remove(id);
    }

    public boolean isGoodFriend(String id) {
        return goodFriendList.contains(id);
    }

    public static String getTargetUid(Conversation singleConversation) {

        if (TextUtils.equals(singleConversation.getSenderUserId(), RXingUtils.getUserId())) {
            return singleConversation.getTargetId();
        } else {
            return singleConversation.getSenderUserId();
        }
    }
}
